C++

您所在的位置:网站首页 cstdio iostream C++

C++

2023-03-31 13:37| 来源: 网络整理| 查看: 265

文章目录 六大部件的关系容器——结构与分类sequence 容器使用容器array——代码案例使用容器vector——代码案例使用容器list——代码案例使用容器forward list——代码案例使用容器deque——代码案例 关联式容器使用容器multiset——代码案例使用容器multimap——代码案例使用容器set——代码案例使用容器map——代码案例 unordered 容器使用容器unordered_multiset——代码案例使用容器unordered_multimap——代码案例

六大部件的关系

在这里插入图片描述

容器——结构与分类

在这里插入图片描述

在这里插入图片描述 set与multiset的区别:set中的key值(key就是value)不可以重复,而multiset可以重复。 实现底层是红黑树,保持高度平衡的二叉树。自动调整

sequence 容器 使用容器array——代码案例 #include #include #include #include //qsort, bsearch, NULL namespace jj01 { void test_array() { cout long target=0; cout cout snprintf(buf, 10, "%d", rand()); c.push_back(string(buf)); //尾部插入,双倍增长 } catch(exception& p) { cout timeStart = clock(); sort(c.begin(), c.end()); cout try { snprintf(buf, 10, "%d", rand()); c.push_back(string(buf)); } catch(exception& p) { cout try { snprintf(buf, 10, "%d", rand()); c.push_front(string(buf)); } catch(exception& p) { cout try { snprintf(buf, 10, "%d", rand()); c.push_back(string(buf)); } catch(exception& p) { cout try { snprintf(buf, 10, "%d", rand()); c.insert(string(buf)); } catch(exception& p) { cout timeStart = clock(); auto pItem = c.find(target); //比 std::find(...) 快很多 cout try { snprintf(buf, 10, "%d", rand()); //multimap 不可使用 [] 做 insertion c.insert(pair(i,buf)); //key为0~1000000,value为随机数 } catch(exception& p) { cout try { snprintf(buf, 10, "%d", rand()); c.insert(string(buf)); } catch(exception& p) { cout timeStart = clock(); auto pItem = c.find(target); //比 std::find(...) 快很多 cout try { snprintf(buf, 10, "%d", rand()); c[i] = string(buf); } catch(exception& p) { cout try { snprintf(buf, 10, "%d", rand()); c.insert(string(buf)); } catch(exception& p) { cout timeStart = clock(); auto pItem = c.find(target); //比 std::find(...) 快很多 cout try { snprintf(buf, 10, "%d", rand()); //multimap 不可使用 [] 進行 insertion c.insert(pair(i,buf)); } catch(exception& p) { cout


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3